<template>
  <div class="kb">
    <header-nav></header-nav>
    <!-- 轮播图 -->
    <div class="rotationchart">
      <div class="imgs">
        <van-swipe :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in imgs" :key="index"
            ><img :src="item.pic"
          /></van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <!-- 滑块 -->
    <div class="DailyRecommendation">
      <div @click="MoreSongs">
        <i class="iconfont icon-wodetuijian"></i>
        <div>每日推荐</div>
      </div>
      <div @click="MoreSongs">
        <i class="iconfont icon-gedan1"></i>
        <div>歌单</div>
      </div>
      <div @click="ranking">
        <i class="iconfont icon-ranking"></i>
        <div>排行榜</div>
      </div>
      <div @click="PopularSinger">
        <i class="iconfont icon-geshou"></i>
        <div>歌手</div>
      </div>
      <div @click="PopularMV">
        <i class="iconfont icon-MV"></i>
        <div>MV</div>
      </div>
    </div>
    <!-- 推荐歌单 -->
    <div class="remlists">
      <div class="title">推荐歌单</div>
      <span class="more" @click="MoreSongs"
        >更多<i class="iconfont icon-xiangyou1"></i
      ></span>
      <div class="content">
        <div class="swiper-container swiper-container-01">
          <div class="swiper-wrapper">
            <div
              class="swiper-slide item"
              v-for="(item, index) in list"
              :key="index"
              v-show="index < 3"
            >
              <router-link
                class="img"
                :to="'/ranking/rankinglist?id=' + item.id"
              >
                <img :src="item.picUrl" alt="" />
              </router-link>
              <p>{{ item.name }}</p>
              <span>
                <span class="iconfont icon-bofang"></span>
                {{ parseInt(item.playCount / 10000) }}万
              </span>
            </div>
          </div>
          <div class="swiper-pagination swiper-pagination-01"></div>
        </div>
      </div>
    </div>
    <!-- 热门歌手 -->
    <div class="playlist">
      <div class="Rap">
        <span>热门歌手</span>
        <div @click="PopularSinger">
          更多<span class="iconfont icon-xiangyou1"></span>
        </div>
      </div>
      <div class="content">
        <div class="swiper-container swiper-container-02">
          <div class="swiper-wrapper">
            <div
              class="swiper-slide item"
              v-for="(item, index) in artistList"
              :key="index"
              v-show="index < 3"
            >
              <router-link
                class="img"
                :to="'/recommend/singerID?id=' + item.id"
              >
                <img :src="item.img1v1Url" />
              </router-link>
              <p>{{ item.name }}</p>
            </div>
          </div>
          <div class="swiper-pagination swiper-pagination-02"></div>
        </div>
      </div>
    </div>
    <!-- 热门MV -->
    <div class="Rap">
      <span>热门MV</span>
      <div @click="PopularMV">
        更多<span class="iconfont icon-xiangyou1"></span>
      </div>
    </div>
    <!-- MV列表 -->
    <div class="vanGrid">
      <div
        v-for="(item, index) in topmv"
        :key="index"
        v-show="index < 6"
        @click="vanGrid"
      >
        <div class="img" :style="'background-image: url(' + item.cover + ')'" />
        <p>{{ item.artistName }}&nbsp;-&nbsp;《{{ item.name }}》</p>
      </div>
    </div>
    <div class="kb"></div>
    <!-- 底部 -->
    <div class="bottom">
      <van-tabbar active-color="#ee0a24" inactive-color="#ccc" v-model="active">
        <van-tabbar-item
          class="iconfont icon-wangyiyunyinle1-copy"
          @click="recommend"
          >首页</van-tabbar-item
        >
        <van-tabbar-item class="iconfont icon-huatong" @click="singers"
          >歌手</van-tabbar-item
        >
        <van-tabbar-item class="iconfont icon-peoples" @click="podcast"
          >关注</van-tabbar-item
        >
        <van-tabbar-item class="iconfont icon-paihang" @click="ranking"
          >榜单</van-tabbar-item
        >
        <van-tabbar-item
          class="iconfont icon-shejiao-yinle-copy"
          @click="$router.push('/userInfo').catch(() => {})"
          >我的</van-tabbar-item
        >
      </van-tabbar>
    </div>
  </div>
</template>
<script>
import Swiper from "swiper";
import headerNav from "../components/headerNav.vue";
import { getBanner, getPersonalizedr } from "../api/recommend";
import { getArtistListType, getMvAll } from "../api/ranking";

export default {
  data() {
    return {
      imgs: null,
      list: null,
      active: 0,
      artistList: null,
      topmv: null,
    };
  },
  created() {
    // 轮播图
    getBanner().then((data) => {
      this.imgs = data.banners;
    });
    getPersonalizedr().then((data) => {
      this.list = data.result;
    });
    getArtistListType().then((data) => {
      this.artistList = data.artists;
    });
    getMvAll().then((data) => {
      console.log(data);
      this.topmv = data.data;
    });
  },
  methods: {
    recommend() {
      this.$router.push("/recommend");
    },
    singers() {
      this.$router.push("/singer");
    },
    ranking() {
      this.$router.push("/ranking");
    },
    podcast() {
      this.$router.push("/podcast");
    },
    MoreSongs() {
      this.$router.push("/recommend/MoreSongs");
    },
    PopularSinger() {
      this.$router.push("/recommend/PopularSinger");
    },
    PopularMV() {
      this.$router.push("/recommend/PopularMV");
    },
    vanGrid() {
      this.$router.push("/recommend/PopularMV");
    },
    RecommendSongs() {
      this.$router.push("/recommend/RecommendSongs");
    },
  },
  mounted() {
    new Swiper(".swiper-container-01", {
      // pagination: '.swiper-pagination-01',
      slidesPerView: 3, //显示个数
      paginationClickable: true,
      observer: true,
      observeParents: true,
      spaceBetween: 10, //div之间间距
    });
    new Swiper(".swiper-container-02", {
      // pagination: '.swiper-pagination-01',
      slidesPerView: 3, //显示个数
      paginationClickable: true,
      observer: true,
      observeParents: true,
      spaceBetween: 10, //div之间间距
    });
  },
  components: { headerNav },
};
</script>
<style lang="less">
.kb {
  .rotationchart {
    height: 124px;
    width: 100%;
    position: relative;
    padding-top: 39px;
    .imgs {
      position: absolute;
      left: 0px;
      right: 0px;
      top: 42px;
      margin: auto;
      width: 95.9%;
      img {
        border-radius: 4px;
        width: 100%;
        z-index: 10;
      }
    }
  }
  .DailyRecommendation {
    width: 97%;
    margin: 0 auto;
    display: flex;
    justify-content: space-around;
    text-align: center;
    padding-top: 15%;
    font-size: 12px;
    border-bottom: 1px solid #ccc;
    div {
      i {
        background-color: #fff0f5;
        border-radius: 50%;
        font-size: 30px;
        color: #ff393c;
        padding: 10px;
      }
      div {
        margin-top: 10px;
        height: 30px;
        line-height: 30px;
      }
    }
  }
  //推荐歌单
  .remlists {
    position: relative;
    width: 97%;
    margin: 0 auto;
    overflow: hidden;
    .title {
      height: 60px;
      line-height: 60px;
      text-indent: 5px;
      font-size: 20px;
      font-weight: bold;
      color: #000;
      font-weight: bold;
    }
    .more {
      border-radius: 10px;
      padding: 2px 8px;
      font-size: 12px;
      position: absolute;
      top: 20px;
      right: 0px;
      color: rgb(172, 172, 172);
      i {
        vertical-align: middle;
        font-size: 10px;
      }
    }
    .content {
      width: 100%;
      height: 21vh;
      .swiper-wrapper {
        display: flex;
        justify-content: flex-end;
        .item {
          // float: left;
          flex: 0 0 30%;
          position: relative;
          span {
            background-color: rgba(131, 129, 129, 0.3);
            position: absolute;
            top: 2px;
            right: 2px;
            color: #fff;
            font-size: 10px;
            line-height: 15px;
            border-radius: 10px;
            padding: 1px 2px;
            i {
              margin: 0 2px;
              font-size: 10px;
              vertical-align: middle;
            }
          }
          .img {
            min-height: 50px;
            width: 100%;
            border-radius: 8px;
            img {
              width: 100%;
              border-radius: 8px;
            }
          }
          p {
            font-size: 12px;
            color: #565658;
            line-height: 15px;
            padding: 3px;
            margin-bottom: 10px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
          }
        }
      }
    }
    .bottom {
      width: 100%;
      height: 30px;
      position: fixed;
      padding: 5px 0;
      left: 0px;
      bottom: 0px;
      z-index: 10;
      background-color: white;
    }
  }
  .playlist {
    margin: 5px auto;
    width: 100%;
    overflow: hidden;
    //歌手
    .content {
      width: 100%;
      height: 20vh;
      .swiper-wrapper {
        display: flex;
        justify-content: flex-end;
        .item {
          flex: 0 0 30%;
          position: relative;
          span {
            background-color: rgba(131, 129, 129, 0.3);
            position: absolute;
            top: 2px;
            right: 2px;
            color: #fff;
            font-size: 10px;
            line-height: 15px;
            border-radius: 10px;
            padding: 1px 2px;
            i {
              margin: 0 2px;
              font-size: 10px;
              vertical-align: middle;
            }
          }
          .img {
            min-height: 50px;
            width: 97%;
            margin: 0 auto;
            border-radius: 50%;
            margin-top: 5px;
            img {
              width: 100%;
              border-radius: 50%;
            }
          }
          p {
            font-size: 16px;
            color: #565658;
            padding: 3px;
            text-align: center;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
          }
        }
      }
    }
  }
  .vanGrid {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    div {
      flex: 0 0 30%;
      .img {
        border-radius: 10px;
        height: 10vh;
        background-size: 100%;
        background-repeat: no-repeat;
      }
      p {
        width: 120px;
        font-size: 12px;
        margin: 10px 0;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
  .kb {
    width: 100%;
    height: 10vh;
  }

  .Rap {
    width: 97%;
    margin: 15px auto 5px auto;
    height: 20px;
    line-height: 20px;
    span {
      font-size: 18px;
      font-weight: 600;
    }
    div {
      border-radius: 10px;
      font-size: 12px;
      padding: 0px 7px;
      float: right;
      color: rgb(172, 172, 172);
      span {
        padding: 0;
        font-size: 12px;
      }
    }
  }
  .swiper-slide.item {
    height: 50px;
  }
}
</style>